cc.Class({
    extends: cc.Component,

    properties: {
        updateItem:cc.Prefab,
        scrollView:cc.ScrollView,
        btn:cc.Node,
        selectSprite:[cc.SpriteFrame],
        backBtn:cc.Node,
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    start () {
        this.back();
        // this.showUpdate();
        // this.pageIndex = 0;
    },
    init(){
        this.showUpdate();
        this.pageIndex = 0;
    },
    showUpdate(){
        this.scrollView.content.removeAllChildren();
        this.scrollView.content.height= 0 ;
        for( var prop in cc.configData.material){
            if(cc.configData.material[prop].level<2){
                var updateItem = cc.instantiate(this.updateItem);
                this.scrollView.content.addChild(updateItem);
                updateItem.getComponent('updateItem').init(cc.configData.material[prop],prop);
            }
        }
    },
    showLock(){
        this.scrollView.content.removeAllChildren();
        this.scrollView.content.height= 0 ;
        for(var prop in cc.configData.lock){
            if(!cc.configData.lock[prop].isUpdate){
                var updateItem = cc.instantiate(this.updateItem);
                this.scrollView.content.addChild(updateItem);
                updateItem.getComponent('updateItem').init(cc.configData.lock[prop],prop);
            }
        }
    },
    back(){
        this.backBtn.on('click',function(){
            this.node.active = false;
        },this)
    },
    btnClick(e,btnIndex){
       this.btn.children[0].getComponent(cc.Sprite).spriteFrame = this.selectSprite[0];
       this.btn.children[0].children[0].color = cc.color(186,162,255);
       this.btn.children[1].getComponent(cc.Sprite).spriteFrame = this.selectSprite[1];
       this.btn.children[1].children[0].color = cc.color(186,162,255);
       this.btn.children[btnIndex].getComponent(cc.Sprite).spriteFrame = null;
       this.btn.children[btnIndex].children[0].color = cc.color(255,255,255);
       this.scrollView.scrollToTop(0);
       if(btnIndex === '0' && this.pageIndex != 0) {
           this.pageIndex = 0;
           this.showUpdate();
       }
       if(btnIndex === '1' && this.pageIndex != 1){
           this.pageIndex = 1;
           this.showLock();
       }
    },
    // update (dt) {},
});
